package com.gzdh.dishrecognition.thead;

import android.app.Activity;

import com.gzdh.dishrecognition.event.TimeEvent;

import org.greenrobot.eventbus.EventBus;

public class TimeThread extends Thread {
    private Activity mActivity;
    private ToChannel toChannel;

    public TimeThread(Activity activity, ToChannel toChannel) {
        this.mActivity = activity;
        this.toChannel = toChannel;
    }

    private int count = 0;

    @Override
    public void run() {
        while (true) {
            try {
                sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if ((count++) > 20) {
                UpLoadOrdersThread upLoadReserveThread = new UpLoadOrdersThread(mActivity);
                new Thread(upLoadReserveThread).start();
                count = 0;
            }


            mActivity.runOnUiThread(() -> {
                if (toChannel != null) {
                    toChannel.linner();
                }
            });
            EventBus.getDefault().post(new TimeEvent());
        }
    }

    public interface ToChannel {
        void linner();
    }
}
